
<html>
<head>
    <title>JLM demo</title>
    <script src="./editor/editor.nocache.js"></script>


    <script>

const urlParams = new URLSearchParams(window.location.search);


var jlmlib;
var latex = "\\sqrt{x}";
var type = 0;
if (urlParams.has('latex')) {
	latex =  urlParams.get('latex') + "";
}
if (urlParams.has('type')) {
	type =  urlParams.get('type') * 1;
}

 function jlmOnInit(api) {
        	console.log("jlmOnInit() - api available");
        	jlmlib = api;

        	if (windowLoaded) {
        		redraw();
        	}
        }

        window.onload = function() {
        	windowLoaded = true;
        	if (jlmlib) {
        		redraw();
        	}
        }


function redraw() {
  document.querySelectorAll(".latexf").forEach(el => {
      const canvas = document.createElement("canvas");
      el.appendChild(canvas);
      const ctx = canvas.getContext("2d");

	                  var opts = {
                    "context": ctx,
                    "latex": latex,
                    "size": 16,
                    "x": 0,
                    "y": 0,
                    "type": type,
                    "foregroundColor": "#000000",
                    "backgroundColor": "#ffffff",
                    "callback" : function() { 	},
                    "insets": {
                        "top": 0,
                        "bottom": 0,
                        "left": 0,
                        "right": 0
                    }
					};


      jlmlib.drawLatex(opts);
  });
}
</script>
</head>
<body>
<div class="latexf"></div>
</body>
</html>
